package fr.bassochette.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class BaseSqlLite extends SQLiteOpenHelper{

	private final static String TABLES_CONSO="conso";
	private final static String ID_CONSO="id";
	private final static String PRIX="prix";
	private final static String NOM="nom";
	private final static String QT="qt";
	
	private final static String CREATE_BDD="CREATE TABLE "+ TABLES_CONSO+"("
			+ID_CONSO+" INTEGER PRIMARY KEY AUTOINCREMENT, "+PRIX+" REAL NOT NULL, "+
			NOM+" TEXT NOT NULL,"+QT+"INTEGER );";
	

	
	public BaseSqlLite(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		Log.d("DBSQLITE", "BASE: TRY ON CREATE");
		db.execSQL(CREATE_BDD);
		Log.d("DBSQLITE", "BASE: SUCCESS ON CREATE");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE "+TABLES_CONSO+";");
		onCreate(db);
	}

}
